﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace OutlookMGI
{
    public partial class ThisAddIn
    {
        Office.CommandBarButton btn1;
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Outlook.Explorer explorer = this.Application.ActiveExplorer();
            Object oMissing = System.Reflection.Missing.Value;
            if (explorer != null)
            {
                Office.CommandBar bar = explorer.CommandBars.Add("MGI", oMissing, oMissing, true);
                bar.Visible = true;
                btn1 = (Office.CommandBarButton)bar.Controls.Add(Office.MsoControlType.msoControlButton, oMissing, oMissing, oMissing, true);
                btn1.Caption = "Alta Incidente";
                btn1.Tag = "myOutlookAddin1.btn1";
                btn1.Style = Office.MsoButtonStyle.msoButtonCaption;
                btn1.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(Btn1_Click);
            }
        }

        private void Btn1_Click(Office.CommandBarButton Ctrl, ref bool Cancel)
        {
            Outlook.MailItem mailSeleccionado = null;
            Outlook.Selection itemSeleccionado;
            
            itemSeleccionado = this.Application.ActiveExplorer().Selection;
            try
            {
                mailSeleccionado = (Outlook.MailItem)itemSeleccionado[1];

            }
            catch (Exception)
            {
                mailSeleccionado = null;
            }
            if (mailSeleccionado != null)
            {
                
                mailSeleccionado.Display(false);
                mailSeleccionado.GetInspector.SetCurrentFormPage("OutlookMGI.IncidentesGUI");
            }
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}
